﻿package org.edu.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;
import org.edu.bean.City;
import org.edu.bean.County;
import org.edu.bean.User;
import org.edu.dao.XZQHDao;

import com.opensymphony.xwork2.ActionSupport;

public class XZQHController extends ActionSupport {
	
	@Resource
	XZQHDao xzqhDao ;
	public String result ;
	private int prId ;
	/**
	 * @exception 根据 province 得到 city
	 * @return
	 */
	public String city(){
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession() ;
		User user = (User)session.getAttribute("user");
		List<City> citys = null ;
		if(user.getWorkCityId() != -1){
			citys = xzqhDao.getCityByCiId(user.getWorkCityId());
		}else{
			City city = new City() ;
			city.setCityid(-1);
			city.setCityname("全省");
			citys = xzqhDao.getCityByPrId(prId);
			citys.add(city);
		}
		JSONArray ja = JSONArray.fromObject(citys);
		result = ja.toString();
		return SUCCESS ;
	}
	private int ciId ;
	
	public String county(){
		
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession() ;
		User user = (User)session.getAttribute("user");
		List<County> counties = null ;
		if(user.getWorkCountyId() != -1){
			counties = xzqhDao.getCountyByCoId(user.getWorkCountyId());
		}else{
			County county = new County() ;
			counties= xzqhDao.getCountyByCiId(ciId);
		}
		
		JSONArray jaArray = JSONArray.fromObject(counties);
		result = jaArray.toString();
		return SUCCESS ;
	}
	
	
	public int getPrId() {
		return prId;
	}
	public void setPrId(int prId) {
		this.prId = prId;
	}
	public int getCiId() {
		return ciId;
	}
	public void setCiId(int ciId) {
		this.ciId = ciId;
	}
	
	
}
